package com.ssm.web;

import com.ssm.Service.showmyfavoritesService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "showmyfavoritesServlet",urlPatterns = "/showmyfavorites")
public class showmyfavoritesServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println("显示收藏夹请求");
        String username=request.getParameter("username");

        showmyfavoritesService showmyfavoritesService=new showmyfavoritesService();

        List<Object> showmyfavorites = showmyfavoritesService.showmyfavorites(username);

        response.setContentType("text/html;charset=utf-8");
        JSONArray data=JSONArray.fromObject(showmyfavorites);
        PrintWriter writer=response.getWriter();
        writer.print(data);
        writer.close();
    }
}
